<?php
/**
 * Created by PhpStorm.
 * User: rain
 * Date: 2019/3/27
 * Time: 11:14 PM
 */

namespace App\Utils;


class FileUtil
{
    public static function getFileSize($url)
    {
        $header_array = get_headers($url, true);
        $size = $header_array['Content-Length'];

        return $size;
    }

    public static function getImageWithHeight($url)
    {
        $Info = getimagesize($url);

        return ['with' => $Info[0], 'height' => $Info[1]];
    }

    public static function getDomain($value)
    {
        return env('FILE_DOMAIN', '') . $value;
    }


    /**
     * 压缩图片
     * @param $url
     * @param int $soWidth
     * @param int $soHeight
     * @return string
     */
    /*public static function solidityImage($url, $soWidth = 2, $soHeight = 2)
    {
        try{

            $path = parse_url($url)['path'];
            $imageInfo = self::getImageWithHeight($url);

            $with = ceil($imageInfo['with'] / $soWidth);

            $height = ceil($imageInfo['height'] / $soHeight);

            $img = \Intervention\Image\ImageManagerStatic::make($url)->resize($with, $height);

            $disk = Storage::disk('oss');

            $tempImg = storage_path(Uuid::uuid() . '.jpg');
            $img->save($tempImg);

            $savePath = 'thumb' . $path;

            $disk->put($savePath, file_get_contents($tempImg));

            return $savePath;
        }catch(\Exception $e){
            return '';
        }

    }*/

}